<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Distribution extends Model
{
    use HasFactory;

    protected $table = 'sp_distribution_2';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //is_delete是否删除  1是 2否
    const DISTRIBUTION_IS_DELETE = 1;//是
    const DISTRIBUTION_NOT_DELETE = 2;//否

    //配送方式列表
    protected function GetDistributionList($pageSize, $where)
    {
        $select = array('d.*', 'oa.username');
        $data = $this
            ->from('sp_distribution_2 as d')
            ->leftjoin('sp_other_admin as oa', 'oa.id', 'd.uid')
            ->select($select)
            ->where($where)
            ->orderBy('d.id', 'desc')
            ->paginate($pageSize);
        $data = $data ? $data->toArray() : array();
        return $data;
    }

    //根据id查询
    protected function GetDistributionById($id)
    {
        $where = array(
            'id' => $id,
        );
        $data = $this
            ->where($where)
            ->first();
        $data = $data ? $data->toArray() : [];
        return $data;
    }

    //添加
    protected function addData($data)
    {
        return $data = $this->insert($data);
    }

    //根据id修改
    protected function editDataById($id, $data)
    {
        $where = array(
            'id' => $id,
        );
        return $data = $this->where($where)->update($data);
    }


}
